package lt.marsrutai.mobile.android.activity.intent;

import java.util.Arrays;
import java.util.List;

import lt.marsrutai.mobile.android.activity.FastestRouteDetailsActivity;
import lt.marsrutai.mobile.android.model.Segment;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;

public class FastestRouteDetailsIntentHolder extends IntentHolder {

    private static final String SEGMENTS = "segments";
    private static final String SCOPE_FOLDER = "scopeFolder";

    public FastestRouteDetailsIntentHolder(Activity sourceActivity) {
        super(sourceActivity, FastestRouteDetailsActivity.class);
    }

    public FastestRouteDetailsIntentHolder(Intent intent) {
        super(intent);
    }

    public FastestRouteDetailsIntentHolder(Bundle bundle) {
        super(bundle);
    }

    public void setSegments(List<Segment> segments) {
        intent.putExtra(SEGMENTS, segments.toArray(new Segment[0]));
    }

    public List<Segment> getSegments() {
        Parcelable[] parcelables = intent.getParcelableArrayExtra(SEGMENTS);
        Segment[] segments = new Segment[parcelables.length];
        for (int i = 0; i < segments.length; i++) {
            segments[i] = (Segment) parcelables[i];
        }
        return Arrays.asList(segments);
    }

    public void setScopeFolder(String scopeFolder) {
        intent.putExtra(SCOPE_FOLDER, scopeFolder);
    }

    public String getScopeFolder() {
        return intent.getStringExtra(SCOPE_FOLDER);
    }

}
